<?php
/*------------------------------------------------------------------------
 # SM Slider - Version 1.1
 # Copyright (c) 2013 YouTech Company. All Rights Reserved.
 # @license - Copyrighted Commercial Software
 # Author: YouTech Company
 # Websites: http://www.magentech.com
-------------------------------------------------------------------------*/

$options = $this->getConfigObject();
$uniqued ='container_slider_'.rand().time();
$smarthelper= Mage::helper('slider/utils');
$list = $this->getProducts();
if(!empty($list)){
	echo $this->getScriptTags();?>
	<?php if(!empty($options->pretext)) { ?>
		<div class="pre-text"><?php echo $options->pretext; ?></div>
	<?php } ?>
	<div id="<?php echo $uniqued; ?>" class="container-slider menu-slider" style="<?php if( $options->anchor == "bottom" ){ echo "margin-bottom:40px;"; }?>">
			<?php if($options->anchor =="top"){?>
			<?php if($options->button_display == 1){?>
			<div class="page-button <?php echo $options->anchor;?> <?php echo $options->control;?>">
				<ul class="control-button">
					<li class="preview">Prev</li>
					<li class="next">Next</li>
				</ul>		
			</div>
			<?php }}?>
	
		<div class="slider not-js cols-6 <?php echo $options->deviceclass_sfx; ?>">
			<div class="vpo-wrap">
				<div class="vp">
					<div class="vpi-wrap">
					<?php foreach($list as $item){
						$_product = Mage::getModel('catalog/product')->load($item['id']);
						$now = date("Y-m-d");
						$newsFrom= substr($_product->getData('news_from_date'),0,10);
						$newsTo=  substr($_product->getData('news_to_date'),0,10);
						$specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice(); 
						$price = Mage::getModel('catalog/product')->load($_product->getId())->getPrice();
						//$saleoff = round(($price - $specialprice)/$price*100) ;				
						?>
						<div class="item">
							<div class="item-wrap">
								<div class="item-img">
									<div class="item-img-info">
										<a href="<?php echo $item['link'];?>" <?php echo $smarthelper->getTargetAttr($options->product_links_target);?> onclick="javascript: return true";>
										<?php if( $options->product_source == "catalog" ){?>
											<img src="<?php echo $item['image'];?>" alt="<?php echo $item['title']; ?>" title="<?php echo $item['title']; ?>" />
										<?php }else{?>
											<img  src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$item['image'] ?>"  alt="<?php echo $item['title'] ?>" />	
										<?php }?>
										</a>
									</div>
									<div class="addto-wrap">
										<?php if($_product->isSaleable()): ?>
											<div class="btn-cart">
												<a title="<?php echo $this->__('Add to Cart') ?>" href="javascript:void(0);" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
												<span><span <?php /* class="icon-plus" */ ?>><?php echo $this->__('Add to Cart') ?></span></span></a>
											</div>
										<?php else: ?>
											<span class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></span>
										<?php endif; ?>	
										<?php if ($this->helper('wishlist')->isAllow()) : ?>
											<div class="btn-wishlist">
												<a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a>
											</div>
										<?php endif; ?>
										<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
											<div class="btn-compare">
												<a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a>
											</div>
										<?php endif; ?>																			
									</div>
									<?php
									if ( $now>=$newsFrom && $now<=$newsTo ){
										echo "<span class='new-product'>new</span>";
									}
									if ($specialprice){
										echo "<span class='sale-product'>sale off</span>";
									}
									//if ($isBestProduct){
										//echo "<span class='bestproduct'>best</span>";
									//}									
									?>
								</div>
								<div class="item-info <?php if( $options->theme == "theme2" ){ echo "item-spotlight"; }?> ">
									<div class="item-inner">
										<?php if( $options->product_title_disp == 1 ){?>
										<div class="item-title">
											<a href="<?php echo $item['link'];?>" <?php echo $smarthelper->getTargetAttr($options->product_links_target);?> onclick="javascript: return true";>
												<?php echo $item['title'];?>
											</a>
										</div>
										<?php }?>
										<div class="item-content">
											<?php if( (int)$options->product_price_disp ){ ?>
												<div class="item-price">
													<div class="sale-price">
													<?php echo $item['price'];?>
													</div>
												</div>
											<?php }?>											
											<?php if($options->product_reviews_count == 1){ ?>
											<div class="item-review">
												<?php echo $item['review']; ?>
											</div><!--end item-review-->
											<?php }	?>				 
										</div>	
										<?php if( $options->theme == "theme2" ){
											if( $options->product_title_disp == 1 || $options->product_description_disp == 1 || $options->product_readmore_disp == 1 ){?>
											<div class="item-bg"></div>				
										<?php }}?>		
									</div>
								</div>						
							</div>
						</div>
					<?php }?>
					</div>
				</div>
			</div>
		</div>
		
		<?php if($options->anchor !="top"){?>
			<?php if($options->button_display == 1){?>
			<div class="page-button <?php echo $options->anchor;?> <?php echo $options->control;?>">
				<ul class="control-button">
					<li class="preview">Prev</li>
					<li class="next">Next</li>
				</ul>		
			</div>
		<?php }}?>
		
	</div>
	<?php if(!empty($options->posttext)) {  ?>
		<div class="post-text"><?php echo $options->posttext; ?></div>
	<?php } ?>
<?php }else {echo $this->__('Has no item to show!');}?>

<script type="text/javascript">
//<![CDATA[
    jQuery(document).ready(function($){
        $('#<?php echo $uniqued;?> .slider').responsiver({
            interval: <?php echo $options->delay;?>,
            speed: <?php echo $options->duration;?>,
            start: <?php echo $options->start -1;?>,
            step: <?php echo $options->scroll;?>,
            circular: true,
            preload: true,
			fx: 'slide',
            pause: 'hover',
            control:{
				prev: '#<?php echo $uniqued;?> .control-button li[class="preview"]',
				next: '#<?php echo $uniqued;?> .control-button li[class="next"]'
            },
			getColumns: function(element){
				var match = $(element).attr('class').match(/cols-(\d+)/);
				if (match[1]){
					var column = parseInt(match[1]);
				} else {
					var column = 1;
				}
				if (!column) column = 1;
				return column;
			}          
        });
    });
//]]>
</script>



